package com.zyj.mds.service;

import com.zyj.mds.config.DataSourceEnum;
import com.zyj.mds.config.DynamicDataSource;
import com.zyj.mds.dao.UselessDataDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class QueryService {

    @Autowired
    private DynamicDataSource dynamicDataSource;
    @Resource
    private UselessDataDao uselessDataDao;

    public void doQuery() {
        System.out.println("第一次查询-------------------------");
        dynamicDataSource.setDataSourceKey(DataSourceEnum.DB1);
        uselessDataDao.findAll().forEach(System.out::println);

        System.out.println();
        System.out.println("第二次查询-------------------------");
        dynamicDataSource.setDataSourceKey(DataSourceEnum.DB2);
        uselessDataDao.findAll().forEach(System.out::println);

    }
}
